package com.yxb.news.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.news.domain.TeachingNews;
import com.yxb.news.service.ITeachingNewsService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 家教资讯Controller
 * 
 * @author 林德炫
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/news/news")
public class TeachingNewsController extends BaseController
{
    @Autowired
    private ITeachingNewsService teachingNewsService;

    /**
     * 查询家教资讯列表
     */
    @PreAuthorize("@ss.hasPermi('news:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingNews teachingNews)
    {
        startPage();
        List<TeachingNews> list = teachingNewsService.selectTeachingNewsList(teachingNews);
        return getDataTable(list);
    }

    /**
     * 导出家教资讯列表
     */
    @PreAuthorize("@ss.hasPermi('news:news:export')")
    @Log(title = "家教资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingNews teachingNews)
    {
        List<TeachingNews> list = teachingNewsService.selectTeachingNewsList(teachingNews);
        ExcelUtil<TeachingNews> util = new ExcelUtil<TeachingNews>(TeachingNews.class);
        util.exportExcel(response, list, "家教资讯数据");
    }

    /**
     * 获取家教资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('news:news:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Long newsId)
    {
        return success(teachingNewsService.selectTeachingNewsByNewsId(newsId));
    }

    /**
     * 新增家教资讯
     */
    @PreAuthorize("@ss.hasPermi('news:news:add')")
    @Log(title = "家教资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingNews teachingNews)
    {
        return toAjax(teachingNewsService.insertTeachingNews(teachingNews));
    }

    /**
     * 修改家教资讯
     */
    @PreAuthorize("@ss.hasPermi('news:news:edit')")
    @Log(title = "家教资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingNews teachingNews)
    {
        return toAjax(teachingNewsService.updateTeachingNews(teachingNews));
    }

    /**
     * 删除家教资讯
     */
    @PreAuthorize("@ss.hasPermi('news:news:remove')")
    @Log(title = "家教资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public AjaxResult remove(@PathVariable Long[] newsIds)
    {
        return toAjax(teachingNewsService.deleteTeachingNewsByNewsIds(newsIds));
    }
}
